home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / CLI_Tools.lha / Tackon.c < prev    next >
C/C++ Source or Header  |  1995-02-03  |  3KB  |  147 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     Tackon.c
  6.  
  7.     DESCRIPTION
  8.     Get three strings on Commandline
  9.     a path, a name and a suffix,
  10.     build a filename from these three
  11.     strings and write it to StdOut
  12.  
  13.     NOTES
  14.     Kickstart 2.0+ required
  15.     compiles w/ Dice 2.07R - inline-pragmas required
  16.     compiles w/ SAS/C v6.51
  17.  
  18.     BUGS
  19.     there is a strange behaviour if compiled w/ DICE;
  20.     - I cannot say why, but If You do not specify
  21.     each input-slot, You will get a Enforcer-Hits;
  22.     for that reason, I'll distribute Chris' SAS-executable
  23.  
  24.  
  25.     TODO
  26.  
  27.     EXAMPLES
  28.     > tackon xx yy zz
  29.     xx/yy.zz
  30.  
  31.     > tackon xx :yy -zz
  32.     :yy-zz
  33.  
  34.     SEE ALSO
  35.     Suffix, PathPart, FilePart
  36.  
  37.     INDEX
  38.  
  39.     HISTORY
  40.     01-08-93 b_noll created
  41.  
  42.     AUTHOR
  43.     Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
  44.     b_noll@informatik.uni-kl.de
  45.  
  46. ******************************************************************************/
  47.  
  48. /**************************************
  49.         Includes
  50. **************************************/
  51.  
  52. #ifndef   EXEC_LIBRARIES_H
  53. # include <exec/libraries.h>
  54. #endif /* EXEC_LIBRARIES_H */
  55.  
  56. #ifndef   CLIB_EXEC_PROTOS_H
  57. # include <clib/exec_protos.h>
  58. #endif /* CLIB_EXEC_PROTOS_H */
  59.  
  60. #ifndef   DOS_DOS_H
  61. # include <dos/dos.h>
  62. #endif /* DOS_DOS_H */
  63.  
  64. #ifndef   CLIB_DOS_PROTOS_H
  65. # include <clib/dos_protos.h>
  66. #endif /* CLIB_DOS_PROTOS_H */
  67.  
  68. #include <proto/dos.h>
  69. #include <proto/exec.h>
  70.  
  71. /**************************************
  72.         Global Variables
  73. **************************************/
  74.  
  75. #define BUF_SIZ 1000
  76.  
  77. #define isalnum(x) ((((x) <= '9') && ((x >= '0'))) || (((x) <= 'Z') && ((x >= 'A'))) || (((x) <= 'z') && ((x >= 'a'))))
  78. #define BODY(x)      do{ x }while(0)
  79. #define findlast(s)  BODY(char*td=(s);while(*td) ++td; (s)=td;)
  80.  
  81. /* #define strcpy(d,s)  BODY(char*td=(d);char*ts=(s);while(*td=*ts) {++td; ++ts;}) */
  82.  
  83. char* mstrcpy(char*, char*);
  84.  
  85. /**************************************
  86.         Implementation
  87. **************************************/
  88.  
  89. long _main (void)
  90. {
  91.     const char*     version = "$VER: Tackon 1.0 (1.8.93)";
  92.     long        retval  = 20;
  93.     struct Library* SysBase = *((struct Library**)4L);
  94.     struct Library* DOSBase;
  95.     char*        b2;
  96.     char*        buffer;
  97.  
  98.     if (buffer = AllocMem(BUF_SIZ, 0)) {
  99.     if (DOSBase = OpenLibrary (DOSNAME, 37)) {
  100.         STRPTR argv[4] = { NULL, NULL, NULL };
  101.         APTR   args;
  102.         retval = 10;
  103.         if (args = (void*)ReadArgs("PATH,NAME/A,SUFFIX", (LONG*)argv, NULL)) {
  104.         retval    = 0;
  105.         *buffer = 0;
  106.  
  107.         mstrcpy (buffer, argv[0]);
  108.  
  109.         if (AddPart (buffer, argv[1], BUF_SIZ-1)) {
  110.             b2 = buffer;
  111.             while (*b2) ++b2;
  112.             if (argv[2] && isalnum(*argv[2])) {
  113.             *b2   = '.';
  114.             ++b2;
  115.             } /* if */
  116.             mstrcpy (b2, argv[2]);
  117.  
  118.             PutStr (buffer);
  119.             PutStr ("\n");
  120.         } /* addpart */
  121.  
  122.         FreeArgs (args);
  123.         } /* if */
  124.         CloseLibrary (DOSBase);
  125.     } /* if */
  126.     FreeMem (buffer, BUF_SIZ);
  127.     } /* if */
  128.     return (retval);
  129. } /* _main */
  130.  
  131. char* mstrcpy(char*d, char*s)
  132. {
  133.     if (s) {
  134.     while (*d=*s) {
  135.         ++d;
  136.         ++s;
  137.     } /* while */
  138.     } /* if */
  139.     return (d);
  140. }
  141.  
  142. /******************************************************************************
  143. *****  END Tackon.c
  144. ******************************************************************************/
  145.  
  146.  
  147.